import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'node:path';
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import qiankun from "vite-plugin-qiankun";
import electron from 'vite-plugin-electron'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    qiankun('first', {
      // 微应用名字，与主应用注册的微应用名字保持一致
      useDevMode: true,
    }),
    electron({
        // 主进程入口文件
        entry: './electron/main.ts'
    })
  ],
  base: './', // 关键！使用相对路径
  build: {
    assetsDir: 'assets', // 确保资源目录正确
  },
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, './src'),
      },
    ],
  },
  server: {
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    host: "0.0.0.0", // ip
    port: 7001,
    origin: "http://localhost:7001",
    proxy: {
      "/v1": {
        target: "http://192.168.1.14:8787",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/v1/, '/v1')
      },
      "/live": {
        target: "https://player.xueqianban.vip",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/live/, '/live')
      },
      
    }
  },
})
